import 'package:flutter/material.dart';
import 'pages/tabs/Info.dart';
import 'pages/tabs/Contact.dart';
import 'pages/tabs/See.dart';

class Tabs extends StatefulWidget {
  Tabs({Key? key}) : super(key: key);

  @override
  _TabsState createState() => _TabsState();
}

class _TabsState extends State<Tabs> {
  int _currentIndex=0;
  List _pageList=[
    Info(),
    Contact(),
    See(),
  ];

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: Text('flutter案例')),
      body: this._pageList[this._currentIndex],
      floatingActionButton: Container(
        width: 70,
        height: 70,
        padding: EdgeInsets.all(6),
        margin: EdgeInsets.only(top:10),
        //设置为圆形
        decoration: BoxDecoration(
          borderRadius: BorderRadius.circular(35),
          //decoration和color不能同级存在，会报错
          color: Colors.white,
        ),
        child: FloatingActionButton(
          child: Icon(Icons.add,color: Colors.black,size: 20,),
          backgroundColor: this._currentIndex==1?Colors.red:Colors.yellow,
          onPressed: () {
            setState(() {
              this._currentIndex=1;
            });
          },
        ),
      ),
      floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked,
      //底部导航
      bottomNavigationBar: BottomNavigationBar(
        currentIndex: this._currentIndex,
        onTap: (int index){
          setState(() {
            this._currentIndex=index;
          });
        },
        // 图标大小
        iconSize: 30.0,
        // 选中图标的颜色
        fixedColor: Colors.blue,
        // 配置底部可以有多个Tab标签页(4个时就需要)
        type: BottomNavigationBarType.fixed,
        items: [
          BottomNavigationBarItem(
            icon: Icon(Icons.add_comment),
            label:'消息',
          ),
          BottomNavigationBarItem(
            icon: Icon(Icons.perm_contact_cal),
            label:'通讯录',
          ),
          BottomNavigationBarItem(
            icon: Icon(Icons.remove_red_eye),
            label:'看点',
          ),
        ],
      ),
      //左侧边栏
      drawer: Drawer(
        child: Column(
          children: <Widget>[
            //抽屉头部
            /*DrawerHeader(
              decoration: BoxDecoration(
                color: Colors.yellow,
                image: DecorationImage(
                  image: NetworkImage('https://www.itying.com/images/flutter/2.png'),
                  fit: BoxFit.cover,
                ),
              ),
              child: ListView(
                children: <Widget>[
                  Text('一个头部'),
                ],
              ),
            ),*/
            UserAccountsDrawerHeader(
              accountName: Text('Tokyo'),
              accountEmail:Text('socalledstrive@163.com'),
              currentAccountPicture: CircleAvatar(
                backgroundImage: NetworkImage('https://www.itying.com/images/flutter/1.png'),
              ),
              decoration: BoxDecoration(
                color: Colors.yellow,
                image: DecorationImage(
                  image: NetworkImage('https://www.itying.com/images/flutter/2.png'),
                  fit: BoxFit.cover,
                ),
              ),
              otherAccountsPictures: <Widget>[
                Image.network('https://www.itying.com/images/flutter/3.png'),
                Image.network('https://www.itying.com/images/flutter/4.png'),
                Image.network('https://www.itying.com/images/flutter/5.png'),
              ],
            ),
            ListTile(
              title: Text('个人中心'),
              leading: CircleAvatar(
                child: Icon(Icons.people),
              ),
              onTap: (){
                Navigator.of(context).pop();//返回时隐藏侧边栏
                Navigator.pushNamed(context, '/search');
              },
            ),
            Divider(),
            ListTile(
              title: Text('系统设置'),
              leading: CircleAvatar(
                child: Icon(Icons.settings)
              ),
            )
          ],
        ),
      ),
      //右侧边栏
      /*endDrawer: Drawer(
        child: Text('右侧边栏'),
      ),*/
    );
  }
}
